package cn.ghf.user.controller;

import cn.ghf.basic.exception.MyException;
import cn.ghf.basic.util.AjaxResult;
import cn.ghf.user.service.IVerifyCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/verifycode")
public class VerifyCodeController {

    @Autowired
    private IVerifyCodeService service;

    /**
     * 手机验证码功能
     * @param phone
     * @return
     */
    @PostMapping("/sendSmsCode")
    public AjaxResult sendSmsCode(@RequestBody Map<String,String> map){
        try {
            service.sendSmsCode(map);
            return AjaxResult.createAjaxResult();
        } catch (MyException e) {
            e.printStackTrace();
            return AjaxResult.createAjaxResult().setMsg(e.getMessage());
        } catch (Exception e) {
            return AjaxResult.createAjaxResult().setMsg("系统错误!");
        }
    }
}
